package io.xxx.walle.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private Integer code;

    private String message;

    private T data;

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(ApplicationException e) {
        this.code = e.getCode();
        this.message = e.getMessage();
    }

    public Result(Exception e) {
        this.code = -1;
        this.message = e.getMessage();
    }

    public boolean isSuccess() {
        return code != null && code == 0;
    }
}
